package com.ylr.basic.config;

import com.ylr.base.framework.service.AsyncService;
import com.ylr.base.framework.service.impl.AsyncServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-04-28 14:42:10
 * className: YlrBasicConfig
 * version: 1.0
 * description:
 *  `@EnableDiscoveryClient`: 服务注册到nacos
 */
@Configuration
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.ylr.basic.framework.feign")
public class YlrBasicConfig {

    @Value("${spring.application.simple-name}")
    private String applicationSimpleName;

    /**
     * 注入异步任务服务类对象
     * @param threadPoolTaskExecutor      异步线程池
     * @return 异步任务服务对象
     */
    @Bean
    public AsyncService asyncService(ThreadPoolTaskExecutor threadPoolTaskExecutor) {
        return new AsyncServiceImpl(applicationSimpleName, threadPoolTaskExecutor, null);
    }
}
